import 'package:flutter/material.dart';

class AppbarDemo extends StatefulWidget {
  const AppbarDemo({Key? key}) : super(key: key);

  @override
  _AppbarDemoState createState() => _AppbarDemoState();
}

class _AppbarDemoState extends State<AppbarDemo> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          automaticallyImplyLeading: false, // 隐藏返回
          actions: [
            Builder(
              builder: (context) {
                return IconButton(
                    onPressed: () {
                      print("菜单项");
                      Scaffold.of(context).showSnackBar(SnackBar(
                        content: Text("菜单"),
                        action: SnackBarAction(
                          label: "Ok",
                          onPressed: () {
                            Scaffold.of(context).hideCurrentSnackBar();
                          },
                        ),
                      ));
                    },
                    icon: Icon(Icons.list));
              },
            ),
            Builder(
              builder: (context) {
                return IconButton(
                    onPressed: () {
                      print("收藏");
                      Scaffold.of(context).showSnackBar(SnackBar(
                        content: Text("收藏"),
                        action: SnackBarAction(
                          label: "Ok",
                          onPressed: () {
                            Scaffold.of(context).hideCurrentSnackBar();
                          },
                        ),
                      ));
                    },
                    icon: Icon(Icons.favorite));
              },
            ),
          ],
          title: Text("AppbarDemo"),
          centerTitle: true,
        ),
      ),
    );
  }
}
